package com.gzedu.module.service.curd.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gzedu.common.sys.service.impl.BaseService;
import com.gzedu.module.dao.curd.ICurdListDao;
import com.gzedu.module.modle.curd.CurdList;
import com.gzedu.module.service.curd.ICurdListService;

@Service
public class CurdListServiceImpl extends BaseService<CurdList> implements ICurdListService{
	@Autowired
	private ICurdListDao curdListDao;
	
	/**
	 * 查询通用列表的信息
	 * @param curdList
	 * @return
	 */
	public List<Map<String,Object>> selectByFormId(CurdList curdList){
		List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
		
		List<CurdList> curdListRes = curdListDao.selectByFormId(curdList);
		if(curdListRes != null && curdListRes.size() > 0){
			StringBuffer colName = new StringBuffer();
			StringBuffer colModel = new StringBuffer();
			Map<String,Object> map = new HashMap<String,Object>();
			for(CurdList curd : curdListRes){
				colName.append("'").append(curd.getList_column()).append("',");
				colModel.append("{name:'").append(curd.getFiled_name()).append("',index:'").append(curd.getFiled_name())
					.append("',width:'80'},");
			}
			map.put("colName", "["+colName.toString()+"]");
			map.put("colModel", "["+colModel.toString()+"]");
			res.add(map);
		}
		return res;
	}

	public List<CurdList> getByListId(CurdList curdList) {
		// TODO Auto-generated method stub
		return curdListDao.getByListId(curdList);
	}

	public List<CurdList> getByFormId(CurdList curdList) {
		// TODO Auto-generated method stub
		return curdListDao.selectByFormId(curdList);
	}

	public int deleteByFormId(CurdList curdList) {
		// TODO Auto-generated method stub
		return curdListDao.deleteByFormId(curdList);
	}
}
